//#include"mgepch.h"
#include "LayerStack.h"


namespace myMiniEngine {
	
	LayerStack::LayerStack(){}

	LayerStack::~LayerStack()
	{
		for (Layer* layer : layers) {
			//layer->OnDetach();
			delete layer;
		}
	}
	void LayerStack::PushLayer(Layer* _layer)
	{
		layers.emplace(layers.begin()+layerInsertIndex, _layer);
		layerInsertIndex++;
	}
	void LayerStack::PushOverlay(Layer* _layer)
	{
		layers.emplace_back(_layer);
	}
	void LayerStack::PopLayer(Layer* _layer)
	{
		auto itr = std::find(layers.begin(), layers.begin() + layerInsertIndex, _layer);
		if (itr != layers.begin() + layerInsertIndex)
		{
			//_layer->OnDetach();
			layers.erase(itr);
			layerInsertIndex--;
		}
	}
	void LayerStack::PopOverlay(Layer* _layer)
	{
		auto itr = std::find(layers.begin() + layerInsertIndex, layers.end(), _layer);
		if (itr != layers.end())
		{
			//_layer->OnDetach();
			layers.erase(itr);
		}
	}
}
